<%@ page session="false" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://myfaces.apache.org/trinidad" prefix="tr"%>
<%@ taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>

<h:panelGroup>
	<fieldset><legend>Lista sprzedawców</legend> 
	<t:dataTable id="salesmanTable" width="100%"
		rowOnMouseOver="this.style.backgroundColor='#e0ffc2'"
		rowOnMouseOut="this.style.backgroundColor='#FFF'"
		binding="#{salesmanController.salesmanListDataTable}"
		value="#{salesmanController.salesmanList}" var="salesman"
		rows="0">
		<t:column sortPropertyName="personid.surname" sortable="true">
			<f:facet name="header">
				<h:outputText value="Nazwisko" />
			</f:facet>
			<h:outputText value="#{salesman.personid.surname}" />
		</t:column>
		<t:column sortPropertyName="personid.firstname" sortable="true">
			<f:facet name="header">
				<h:outputText value="Imię" />
			</f:facet>
			<h:outputText value="#{salesman.personid.firstname}" />
		</t:column>
		<t:column sortPropertyName="personid.email" sortable="true">
			<f:facet name="header">
				<h:outputText value="Email" />
			</f:facet>
			<h:outputText value="#{salesman.personid.email}" />
		</t:column>
		<t:column sortPropertyName="personid.login" sortable="true">
			<f:facet name="header">
				<h:outputText value="Login" />
			</f:facet>
			<h:outputText value="#{salesman.login}" />
		</t:column>
		<t:column>
			<f:facet name="header">
				<h:outputText value="Data rejestracji" />
			</f:facet>
			<h:outputText value="#{salesman.registrationdate}">
				<f:convertDateTime pattern="dd-MM-yyyy hh:mm:ss" />
			</h:outputText>
		</t:column>
		<t:column>
			<f:facet name="header">
				<h:outputText value="Nieaktywny" />
			</f:facet>
			<tr:selectBooleanCheckbox value="#{salesman.inactive}" readOnly="true"/>
		</t:column>
		<t:column>
			<f:facet name="header">
				<h:outputText value="Edytuj" />
			</f:facet>
			<tr:commandLink inlineStyle="margin-right:10px" shortDesc="Edytuj"
				rendered="#{currentUserTO.currentSalesman.permissionMap.SALESMAN_EDIT or
							salesman.id == currentUserTO.currentSalesman.id}"
				action="#{salesmanController.updateSalesman}">
				<tr:image source="gfx/edit.png" />
			</tr:commandLink>
		</t:column>
		<t:column>
			<f:facet name="header">
				<h:outputText value="Usuń" />
			</f:facet>
			<tr:commandLink shortDesc="Usuń"
				rendered="#{currentUserTO.currentSalesman.permissionMap.SALESMAN_REMOVE and 
							salesman.id != currentUserTO.currentSalesman.id}"
				action="#{salesmanController.removeSalesman}"
				onclick="return confirmMessageBox('Czy chcesz usunąć sprzedawcę #{salesman.personid.firstname} #{salesman.personid.surname} ?');">
				<tr:image source="gfx/delete.png" />
			</tr:commandLink>
		</t:column>
	</t:dataTable></fieldset>
	<table cellpadding="0" cellspacing="2" width="100%">
		<tr>
			<td align="left">
				<tr:commandButton text="Dodaj sprzedawcę" immediate="true"
									rendered="#{currentUserTO.currentSalesman.permissionMap.SALESMAN_ADD}"
									action="#{NavigationUtil.goToSalesmanForm}"
									inlineStyle="background-color:orange;margin-left:10px" />
			</td>
			<td align="right"></td>
		</tr>
	</table>
</h:panelGroup>